package com.oolatina.adapters;

import java.util.ArrayList;
import java.util.HashMap;

import com.oolatina.R;
import com.oolatina.views.RemoteImageView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class VideoListAdapter extends BaseAdapter {
    private Context mContext;
	private LayoutInflater inflater;
	private ViewHolder holder;
	private String[] mLabels;
	private ArrayList<HashMap<String, String>> mData;

    public VideoListAdapter(Context c, ArrayList<HashMap<String, String>> data) {
        mContext = c;
        mData = data;
        		
        try{
			inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		}catch(Exception e){}
    }

    public int getCount() {
        return mData.size();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }
    
    static class ViewHolder {
		public RemoteImageView image;
		public TextView label;
	}

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
        	convertView = inflater.inflate(R.layout.layout_videolist_row, null);
            holder = new ViewHolder();
            holder.image = (RemoteImageView) convertView.findViewById(R.id.image);
            holder.label = (TextView) convertView.findViewById(R.id.label);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if(position%2==0)
        	convertView.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.selector_videolist_option1));
        else
        	convertView.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.selector_videolist_option2));
        
        holder.image.loadImmediate(mData.get(position).get("thumbnail"));
        holder.label.setText(mData.get(position).get("title"));
        return convertView;
    }

}
